package com.ningmengs789.live.live.live.common.widget.red;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ningmengs789.live.R;
import com.ningmengs789.live.live.live.common.widget.gift.utils.OnItemClickListener;
import com.ningmengs789.live.live.response.BonusReceivedList;
import com.ningmengs789.live.server.widget.CircleImageView;
import com.ningmengs789.live.utils.CommonUtils;
import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

public class HistoryRPAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<BonusReceivedList.ListBean> mList = new ArrayList<>();
    private LayoutInflater layoutInflater;
    private Context context;
    private OnItemClickListener mItemClickListener;

    public HistoryRPAdapter(Context context, OnItemClickListener itemClickListener){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        mItemClickListener = itemClickListener;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new Vh(layoutInflater.inflate(R.layout.history_rp_list, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((Vh) holder).setData(mList.get(position));
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public void setCards(List<BonusReceivedList.ListBean> list) {
        if (list == null) {
            return;
        }
        mList = list;
    }

    class Vh extends RecyclerView.ViewHolder implements View.OnClickListener {

        CircleImageView mAvatar;
        TextView mName;
        TextView mDescribe;
        TextView mMoney;

        public Vh(View itemView) {
            super(itemView);
            mAvatar = itemView.findViewById(R.id.avatar);
            mName = itemView.findViewById(R.id.name);
            mDescribe = itemView.findViewById(R.id.describe);
            mMoney = itemView.findViewById(R.id.money);

            itemView.setOnClickListener(this);
        }

        void setData(BonusReceivedList.ListBean bean) {
            Glide.with(context)
                    .load(CommonUtils.getUrl(bean.getAvatar()))
                    .into(mAvatar);

            mName.setText(bean.getUser_nickname());
            mDescribe.setText(bean.getCreate_time());
            mMoney.setText("" + bean.getMoney());
        }

        @Override
        public void onClick(View v) {
            if (mItemClickListener != null){
                mItemClickListener.onItemClick(null, getLayoutPosition());
            }
        }
    }



}
